package com.servlet;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import net.sf.json.JSONArray;
import net.sf.json.JSONException;
import net.sf.json.JSONObject;


import java.io.IOException;

/**
 * @author Mathison
 * @Title: SearchServlet
 * @Package: com.servlet
 * @Description: 返回搜索结果并跳转搜索页面
 * @date 2021/11/16 18:35
 **/

@WebServlet(name = "SearchServlet", value = "/SearchServlet")
public class SearchServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//        System.out.println("test Here");
        request.setCharacterEncoding("utf-8");
        String keyword = request.getParameter("keyword");

        JSONObject json = new JSONObject();
        JSONArray obj = new JSONArray();

        json.put("keyword",keyword);
        obj.add(json);
        response.getWriter().print(obj);
    }
}
